Skip to content

#3740 - Fix to Style MaterialDesignSwitchToggleButton #3776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

TWhidden
Copy link
Contributor

Fix: Add Default From Value to UncheckedStoryboard DoubleAnimations in MaterialDesignSwitchToggleButton

This PR resolves the issue reported in #3740, where the MaterialDesignSwitchToggleButton caused a System.InvalidOperationException due to the DoubleAnimation using an undefined origin value of NaN.

The solution introduces a From value of 0 to the Width and Height animations in the UncheckedStoryboard, ensuring that the animations have a valid starting value even if the Tag binding is unavailable at runtime. This prevents the exception while preserving the intended visual behavior of the control.


Changes Made

The following lines were updated in MaterialDesign3.ToggleButton.xaml:

<DoubleAnimation Storyboard.TargetName="Thumb"
                 Storyboard.TargetProperty="Width"
                 From="0"
                 To="{Binding Tag, ElementName=SwitchGrid}"
                 Duration="0" />
<DoubleAnimation Storyboard.TargetName="Thumb"
                 Storyboard.TargetProperty="Height"
                 From="0"
                 To="{Binding Tag, ElementName=SwitchGrid}"
                 Duration="0" />

Testing

The fix has been tested using the sample provided in the issue discussion. The problem is resolved without any visible differences in the animations or behavior of the control, including with both default and custom content.


Additional Notes

  • The From="0" approach was preferred over a FallbackValue as it directly addresses the problem at the animation level.
  • The other animations in the control do not appear to require similar changes.
  • Credit to @TWhidden, @corvinsz, and @nicolaihenriksen for the investigation and solution brainstorming.

Checklist

  • Issue referenced in the PR description.
  • Changes tested with provided reproduction steps.
  • Style guidelines followed for MaterialDesignInXamlToolkit.
  • Unit tests not applicable (styling-related fix).
  • Ready for review by maintainers.

…tton 'System.Windows.Media.Animation.DoubleAnimation' cannot use default origin value of 'NaN' in UncheckedStoryboard when using DynamicResource
@Keboo Keboo added this to the 5.3.0 milestone Jan 24, 2025
Copy link
Member

@Keboo Keboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!
And thank you @corvinsz, and @nicolaihenriksen for your reviews.

@dcga
Copy link

dcga commented Mar 3, 2025

You saved my ass with this, I was going crazy.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants